﻿using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;

public class USEditorUtility : Editor
{
    private static GUISkin uSeqSkin;

    public static bool DoRectsOverlap(Rect RectA, Rect RectB)
    {
        return ((((RectA.xMin < RectB.xMax) && (RectA.xMax > RectB.xMin)) && (RectA.yMin < RectB.yMax)) && (RectA.yMax > RectB.yMin));
    }

    public static int FindKeyframeIndex(AnimationCurve curve, Keyframe keyframe)
    {
        for (int i = 0; i < curve.keys.Length; i++)
        {
            if (curve.keys[i].Equals(keyframe))
            {
                return i;
            }
        }
        return -1;
    }

    public static System.Type[] GetAllSubTypes(System.Type aBaseClass)
    {
        List<System.Type> list = new List<System.Type>();
        foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
        {
            foreach (System.Type type in assembly.GetTypes())
            {
                if (type.IsSubclassOf(aBaseClass))
                {
                    list.Add(type);
                }
            }
        }
        return list.ToArray();
    }

    public static GUISkin USeqSkin
    {
        get
        {
            if (uSeqSkin == null)
            {
                string path = "USequencerProSkin";
                if (!EditorGUIUtility.isProSkin)
                {
                    path = "USequencerFreeSkin";
                }
                uSeqSkin = Resources.Load(path, typeof(GUISkin)) as GUISkin;
            }
            if (uSeqSkin == null)
            {
                Debug.LogError("Couldn't find the uSequencer Skin, it is possible it has been moved from the resources folder");
            }
            return uSeqSkin;
        }
    }
}

